class Solution {
public:
    int numberOfWeakCharacters(vector<vector<int>>& properties) {
        sort(properties.begin(), properties.end(), [&](const vector<int>& a, vector<int>& b)
        {
            if(a[0] != b[0])
                return a[0] > b[0];
            else
                return a[1] < b[1];
        });
        int ans = 0;
        int maxElement = 0;
        for(auto i : properties)
        {
            if(i[1] < maxElement)
                ans ++;
            else
                maxElement = i[1];
        }
        return ans;
    }
};
